home *** CD-ROM | disk | FTP | other *** search
- /*
- HASUtilFiles.c from Hsoi's App Shell. © 1995-1997 John C. Daub. All rights reserved
-
- This file contains various "utility" functions used with our file handling routines.
- More file related functions can be found in HASFiles.c
- */
-
- #pragma mark ••• #includes •••
-
- #ifndef _WASTE_
- #include "WASTE.h"
- #endif
- #include "HASGlobals.h"
- #ifndef __HSOIS_APP_SHELL__
- #include "HASMain.h"
- #endif
- #include "HASDialogs.h"
- #include "HASUtilFiles.h"
- #include "HASMiscEvents.h"
-
- #pragma mark -
-
- /*
- * When saving a file, this function will set the default place for the user to
- * save their file. Just a couple low-mem manipulations...
- */
-
-
-
- void HsoiSetDefaultDirectory( const FSSpec *spec )
- {
- LMSetCurDirStore( spec->parID );
- LMSetSFSaveDisk( -spec->vRefNum );
-
- return;
- }
-
- /*
- * This is the dialog filter used for the Get/Put File dialogs. It is very similar to
- * "regular" dialog filters, however we cannot use hsoiMyStandardDialogFilter for the
- * get/put file dialogs due to the SetDialogDefaultItem call (which messes up the
- * put file's cancel/replace dialog...try it and you'll see
- */
-
- pascal Boolean hsoiMySFDialogFilter( DialogRef dialog, EventRecord *event, short *item, void *yourData )
- {
- #pragma unused ( yourData )
-
- GrafPtr savePort;
- ModalFilterUPP stdFilter = nil;
- Boolean reply = false;
- OSErr err;
- short whatEvent;
- Boolean handled = false;
-
- // set up the port
-
- GetPort( &savePort );
- SetGrafPortOfDialog( dialog );
-
- // intercept window events directed to widnows behind the dialog
-
- if ( ( event->what == updateEvt ) || ( event->what == activateEvt ) )
- {
- whatEvent = event->message;
- if ( (DialogRef)(event->message) != dialog )
- {
- if ( event->what == updateEvt )
- HsoiDoUpdate( (WindowRef)(event->message) );
- else if ( event->what == activateEvt )
- HsoiDoActivate( (event->modifiers & activeFlag != 0), (WindowRef)(event->message) );
-
- } // end if (WindowRef)whatEvent != dialog
-
- }
-
- // call the standard Dialog Manager filter procedure
-
-
- err = GetStdFilterProc( &stdFilter );
- if ( (err == noErr) && (!handled) )
- reply = CallModalFilterProc( stdFilter, dialog, event, item );
-
- // restore the port
- SetPort( savePort );
-
- return reply;
-
- }
-
-
- /* The following 2 functions (CheckObjectLock and FSpCheckObjectLock) were taken
- from MoreFiles 1.2.1, a code sample from Apple's DTS. Here's some info from
- the MoreFiles readme:
-
- A collection of File Manager and related routines
-
- by Jim Luther, Apple Macintosh Developer Technical Support
- with significant code contributions by Nitin Ganatra, Apple Macintosh Developer
- Technical Support
- MoreFile Reference is by Eric Soldan
- Copyright © 1992-1994 Apple Computer, Inc.
- All rights reserved.
-
- Frankly, this is one amazing repository of all sorts of file-related things. I'd
- check it out if you can. (should be, as of this writing, on ftp.info.apple.com
- in like the /Apple.Support.Services/Developer_Support/ or something like that).
- Also, I think it's now being made available on the CodeWarrior CD's...check the
- Reference CD.
-
- As of this writing (February 20, 1996), MoreFiles is in version 1.4.1.
- thanx to Alex Rosen for answering my post on comp.sys.mac.programmer.help and pointing
- out MoreFiles to me.
-
- WHAT DO THEY DO? Oh duh...i should tell you huh?
-
- Both functions do the same thing: check to see if the object is locked
- (in this case, the object is a file). This is using in HsoiWriteTextFile()
- to prevent overwriting/deleting locked files.
-
- The only difference between these 2 functions are the arguments passed.
- the first takes a vRefNum, dirID and a file name, the second takes an FSSpec
- and then just calls the first based on the FSSpec (just makes for slighly
- neater/readable code)
- */
-
- pascal OSErr HsoiCheckObjectLock(short vRefNum, long dirID, StringPtr name)
- {
- CInfoPBRec pb;
- OSErr error;
-
- pb.hFileInfo.ioNamePtr = name;
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- pb.hFileInfo.ioFDirIndex = 0; // use ioNamePtr and ioDirID
- error = PBGetCatInfoSync(&pb);
-
- if ( error == noErr )
- {
- // check locked bit
- if ( (pb.hFileInfo.ioFlAttrib & 0x01) != 0 )
- error = fLckdErr;
- }
- return ( error );
- }
-
- /*****************************************************************************/
-
- pascal OSErr HsoiFSpCheckObjectLock(const FSSpec *spec)
- {
- return ( HsoiCheckObjectLock(spec->vRefNum, spec->parID, (StringPtr)spec->name) );
- }
-
-
-